import router from '@system.router';

export default {
    data: {
        times: ["07:00", "12:00", "17:00", "22:00"],
        motions: [
            {
                icon: "motion", label: "活动", ratio: 0
            },
            {
                icon: "motionless", label: "静止", ratio: 0
            }]
    },
    rand(min, max) {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    },
    ratios(motions) {
        for (let i = 0; i < motions.length; ++i) {
            this.motions[motions[i]].ratio++;
        }


        this.motions[0].ratio = Math.round(this.motions[0].ratio / motions.length * 100);
        this.motions[1].ratio = Math.round(this.motions[1].ratio / motions.length * 100);
    },
    onInit() {
        let motions = [];
        for (let i = 0; i < 20; ++i) {
            motions.push(this.rand(0, 1));
        }
        this.ratios(motions);
    },
    onSwipe(e) {
        switch (e.direction) {
            case "left":
                router.replace({
                    uri: "pages/index/index"
                });
                break;

            case "down":
                router.replace({
                    uri: "pages/heartrate/heartrate"
                });
                break;
        }
    }
}
